home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / toolbox / avsmooth < prev    next >
Text File  |  1995-03-20  |  1KB  |  53 lines

  1. %AVSMOOTH Median smoothing filter.
  2. %       [y] = AVSMOOTH(X,L) smooths the input vector X using a
  3. %       median filter with a rectangular window of "L" samples.
  4. %
  5. %       See also: SP_STENG, SP_STMAG, SP_STZCR, MDSMOOTH
  6. %
  7.  
  8. %       Matlab original by:
  9. %       LT Dennis W. Brown 7-11-93, DWB 8-17-93
  10. %       Naval Postgraduate School, Monterey, CA
  11. %       May be freely distributed.
  12. %       Not for use in commercial products.
  13.  
  14. avsmooth = function ( x , L )
  15. {
  16.   local ( x , L )
  17.  
  18.   % default output
  19.   y = [];
  20.  
  21.   % check args
  22.   if (nargs != 2)
  23.   {
  24.     error("avsmooth: Invalid number of input arguments...");
  25.   }
  26.  
  27.   % figure out if we have a vector
  28.   if (min(size(x)) != 1)
  29.   {
  30.     error("avsmooth: Input arg \"x\" must be a 1xN or Nx1 vector.");
  31.   }
  32.  
  33.   % work with Nx1 vectors
  34.   x = x[:];
  35.  
  36.   % number of samples
  37.   Ns = length(x);
  38.  
  39.   % room for output
  40.   y = zeros(Ns,1);
  41.  
  42.   % pad ends to compensate for filter length
  43.   x = [zeros(L/2,1); x ; 0 ; zeros(L/2+1,1)];
  44.  
  45.   % average filter
  46.   for (k in 1:Ns)
  47.   {
  48.     y[k;1] = mean(x[k:k+L-1;1]);
  49.   }
  50.  
  51.   return y;
  52. };
  53.